package com.qi.demo01.UnSafe;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author zjq
 * @date 2020/3/25 21:42
 */
public class CallableTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //new THread(new Runable()).start();
        //new Thread(new FutureTask<V>()).start();
        ////new Thread(new FutureTask<V>(Callable)).start();

        // new Thread().start();//怎么启动Callable
        MyThread myThread = new MyThread();
        FutureTask futureTask = new FutureTask(myThread);
        new Thread(futureTask, "A").start();
        new Thread(futureTask, "B").start();//提前缓存，效率提高
        String s = (String) futureTask.get();   //可能会产生阻塞 或者使用异步通信来处理
        System.out.println(s);
    }
}

class MyThread implements Callable<String> {
    @Override
    public String call() {
        return "123";
    }
}